package com.dks.util;

import java.time.*;

/**
 * 时间相关工具类
 */
public class TimeUtils {

    /**
     * 获取本周的开始时间
     * @author evan
     */
    public static LocalDateTime getStartTimeOfWeek(){
        return LocalDateTime.of(LocalDate.now().with(DayOfWeek.MONDAY), LocalTime.MIN);
    }

    /**
     * 获取本周的结束时间
     * @author evan
     */
    public static LocalDateTime getEndTimeOfWeek(){
        return LocalDateTime.of(LocalDate.now().with(DayOfWeek.SUNDAY), LocalTime.MAX);
    }


    /**
     * 获取指定日期所在周的开始时间
     * @author evan
     */
    public static LocalDateTime getStartTimeOfWeek(LocalDate localDate){
        return LocalDateTime.of(localDate.with(DayOfWeek.MONDAY), LocalTime.MIN);
    }

    /**
     * 获取指定日期所在周的结束时间
     * @author evan
     */
    public static LocalDateTime getEndTimeOfWeek(LocalDate localDate){
        return LocalDateTime.of(localDate.with(DayOfWeek.SUNDAY), LocalTime.MAX);
    }

    public static void main(String[] args) {
        System.out.println(getStartTimeOfWeek(LocalDate.now()));
        System.out.println(getEndTimeOfWeek(LocalDate.now()));
    }

}
